Sort distances in increasing order
Sort an array and make the same interchanges in an auxiliary array.
Description of Parameters
distance - array of values to be sorted
dist_sort - array to be carried with distance (all swaps of distance elements are
matched in dist_sort . After the sort ind_vec contains the original
position of the value i in the unsorted distance array and ind_vec_sort the
initial indexes once sorted
nest - number of stations to be sorted
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
double precision, | intent(in), | DIMENSION(nest) | :: | distance | ||
integer, | intent(in), | DIMENSION(nest) | :: | ind_vec | ||
integer, | intent(in) | :: | nest | |||
double precision, | intent(out), | DIMENSION(nest) | :: | dist_sort | ||
integer, | intent(out), | DIMENSION(nest) | :: | ind_vec_sort |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | i | ||||
integer, | public | :: | iswap | ||||
integer, | public | :: | iswap1 | ||||
integer, | public | :: | itemp | ||||
double precision, | public, | DIMENSION(nest) | :: | temp |
SUBROUTINE Sort (distance,ind_vec,nest,dist_sort,ind_vec_sort) IMPLICIT NONE ! Calling variables INTEGER, INTENT(IN) :: nest DOUBLE PRECISION, DIMENSION(nest), INTENT(IN) :: distance DOUBLE PRECISION, DIMENSION(nest), INTENT(OUT) :: dist_sort INTEGER, DIMENSION(nest), INTENT(IN) :: ind_vec INTEGER, DIMENSION(nest), INTENT(OUT) :: ind_vec_sort ! Local variables INTEGER :: i, iswap, itemp, iswap1 DOUBLE PRECISION, DIMENSION(nest) :: temp ! dist_sort=distance ind_vec_sort=ind_vec ! MINLOC is a FORTRAN 90 function that returns the index value for the ! minimum element in the array DO i=1,nest-1 iswap=MINLOC(dist_sort(i:nest),dim=1) iswap1=iswap+i-1 IF(iswap1 .NE. i) THEN temp(i)=dist_sort(i) dist_sort(i)=dist_sort(iswap1) dist_sort(iswap1)=temp(i) itemp=ind_vec_sort(i) ind_vec_sort(i)=ind_vec_sort(iswap1) ind_vec_sort(iswap1)=itemp ENDIF ENDDO END SUBROUTINE SORT